package com.example.demo.config;


import com.example.demo.common.AppVariable;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class AppConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptort())
                .addPathPatterns("/**")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/editor.md/**")
                .excludePathPatterns("/java_gobang/image/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/image/code.png")
                .excludePathPatterns("/login.html")
                .excludePathPatterns("/register.html")
                .excludePathPatterns("/user/getcode")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/reg")
                .excludePathPatterns("/excessive.html")
                .excludePathPatterns("/secret_update.html")
                .excludePathPatterns("/user/checkuser")
                .excludePathPatterns("/user/updatesecret")
                .excludePathPatterns("/update_secret.html")
                .excludePathPatterns("/user/initques")
                .excludePathPatterns("/user/juganswer")
                .excludePathPatterns("/user/judgesecret")
                .excludePathPatterns("/photo/**");
    }

    /**
     *  静态资源映射
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/photo/**")
                .addResourceLocations("file:///"+ AppVariable.UPLOADS_PATH);
    }

}
